﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace InfoPathTranslate
{
    /// <summary>
    /// 显示读取文件对话框
    /// </summary>
    public class ImportFileDialog
    {
        /// <summary>
        /// 默认文件扩展名
        /// </summary>
        public static string DefaultExtension
        {
            get;
            set;
        }

        /// <summary>
        /// 需要读取的文件名称
        /// </summary>
        public string FileName
        {
            get;
            private set;
        }

        public ImportFileDialog()
        {

        }


        /// <summary>
        /// 运行具有指定所有者的打开文件对话框。
        /// </summary>
        /// <param name="owner"></param>
        /// <returns></returns>
        public DialogResult ShowDialog(IWin32Window owner)
        {
            using (OpenFileDialog dlg = new OpenFileDialog())
            {
                dlg.CheckFileExists = true;
                dlg.DefaultExt = "xsn";
                dlg.Filter = string.Format("数据文件(*.{0})|*.{0}", "xsn");
                dlg.SupportMultiDottedExtensions = true;
                dlg.Title = "读取";

                DialogResult dlgResult = dlg.ShowDialog(owner);
                if (dlgResult == DialogResult.OK)
                {
                    this.FileName = dlg.FileName;
                }

                return dlgResult;
            }
        }
    }
}
